< previous page page_678 next page >

Page 678
The Len() Function Versus an Empty String
Using the Len() function to check for an empty string is about 30 percent faster than using the <> or = sign:
9f31265bb40b592b1929e18a47ab28e5.gif
If strTest <> "" Then
   ...
End If
The following code does the same thing but is more efficient:
9f31265bb40b592b1929e18a47ab28e5.gif
If Len(strTest) Then
   ...
End If
This second code is faster because it doesnt take as much time to count the number of bytes that make up a string as it does to compare every character in one string against every character in another string. Even when the string is blank, the <> operator has to still do a comparison. In addition, the not equal (<>) sign is not a very efficient operator. Of course, I think you lose a little readability by using the Len() function.
Don't Compare Variables for Not Equal to Zero
If youre checking a numeric value against 0, its faster just to check the variable with an If statement:
9f31265bb40b592b1929e18a47ab28e5.gif
If intTest <> 0 Then
   ...
End If
The following statement is equivalent to the first, but it runs faster (you will lose some readability, however):
9f31265bb40b592b1929e18a47ab28e5.gif
If intTest Then
   ...
End If
Use For. . .Each Instead of For. . .Next
To loop through a collection of objects, use the For...Each construct instead of the For...Next looping construct:
9f31265bb40b592b1929e18a47ab28e5.gif
For lngLoop = 0 To 10000
   For intLoop = 0 To Forms.Count - 1

 
< previous page page_678 next page >

If you like this book, buy it!